package com.example.prison.mapper;

import com.example.prison.entity.PeopleManage;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.prison.entity.VisitorAppointment;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author jiang
* @description 针对表【people_manage】的数据库操作Mapper
* @createDate 2024-06-03 16:13:21
* @Entity com.example.prison.entity.PeopleManage
*/
@Mapper
public interface PeopleManageMapper extends BaseMapper<PeopleManage> {

    @Select("<script>select * from people_manage " +
            " <where> " +
            " <if test=\"name != null and name != ''\">and name like concat('%',#{name},'%') </if> " +
            " <if test=\"unit != null and unit != ''\">and unit like concat('%',#{unit},'%') </if> " +
            " <if test=\"post != null and post != ''\">and post like concat('%',#{post},'%') </if> " +
            " <if test=\"status != null and status != ''\">and status like concat('%',#{status},'%') </if> " +
            " <if test=\"phone != null and phone != ''\">and phone like concat('%',#{phone},'%') </if> " +
            " <if test=\"idCard != null and idCard != ''\">and id_card like concat('%',#{idCard},'%') </if> " +
            " </where> " +
            "order by id desc</script>")
    List<PeopleManage> get(@Param("name")String name, @Param("unit")String unit, @Param("post")String post,
                                 @Param("status")String status, @Param("phone")String phone, @Param("idCard")String idCard);

    @Insert("insert into people_manage(name, id_card, phone, gender, unit, post, status, native_place, nationality, address) " +
            "values (#{name}, #{idCard}, #{phone}, #{gender}, #{unit}, #{post}, #{status}, #{nativePlace}, #{nationality}, #{address})")
    int add(PeopleManage data);

    @Delete("<script>delete from people_manage where id in <foreach collection=\"ids\" item=\"item\" open=\"(\" separator=\",\" close=\")\">#{item} </foreach> </script>")
    void deleting(@Param("ids") Integer[] ids);

//    @Update("update people_manage set name=#{data.name},id_card=#{data.idCard},phone=#{data.phone}," +
//            "gender=#{data.gender},unit=#{data.unit},post=#{data.post},status=#{data.status}," +
//            "native_place=#{data.nativePlace},nationality=#{data.nationality},address=#{data.address}" +
//            "where id = #{id}")
    @Update({"<script> UPDATE people_manage",
            "<set>",
            "<if test='data.name != null'>name = #{data.name},</if>",
            "<if test='data.idCard != null'>id_card = #{data.idCard},</if>",
            "<if test='data.phone != null'>phone = #{data.phone},</if>",
            "<if test='data.gender != null'>gender = #{data.gender},</if>",
            "<if test='data.unit != null'>unit = #{data.unit},</if>",
            "<if test='data.post != null'>post = #{data.post},</if>",
            "<if test='data.status != null'>status = #{data.status},</if>",
            "<if test='data.nativePlace != null'>native_place = #{data.nativePlace},</if>",
            "<if test='data.nationality != null'>nationality = #{data.nationality},</if>",
            "<if test='data.address != null'>address = #{data.address},</if>",
            "</set>",
            "where id = #{id} </script>"})
    int updating(PeopleManage data, Integer id);

    @Select("select * from people_manage where id=#{id}")
    PeopleManage getById(@Param("id") Integer id);

    @Select("select * from people_manage where unit=#{unit}")
    List<PeopleManage> getListByUnit (@Param("unit") String unit);

    @Select("select * from people_manage where id_card=#{idCard}")
    List<PeopleManage> getListByIdCard (@Param("idCard") String idCard);

    @Select("select * from people_manage where id_card=#{idCard}")
    PeopleManage getOnePersonnelByIDCard(@Param("idCard") String IdCard);

    @Select("select * from people_manage where name=#{name} and status=#{status}")
    List<PeopleManage> getByStatusAndName(@Param("name")String name, @Param("status")String status);

    @Select("select * from people_manage where name=#{name}")
    List<PeopleManage> getOneListByName(@Param("name")String name);

    @Select("select * from people_manage where post=#{post}")
    List<PeopleManage> getByPost(@Param("post")String post);

    @Select("select * from people_manage where unit=#{unit}")
    List<PeopleManage> getByUnit(@Param("unit")String unit);

    @Select("select * from people_manage where phone=#{pid}")
    PeopleManage getByPID(@Param("pid")String pid);

}




